package fnord.jovian.tango;

import java.util.Vector;

public class TheCompassLayout extends TheLayout {
	
	public enum TheCompassOrientation implements TheOrientation {NORTH,SOUTH,EAST,WEST,NORTHEAST,NORTHWEST,SOUTHEAST,SOUTHWEST,CENTER};
	private int _padding = 50;
	
	public TheCompassLayout() {}
	
	public TheCompassLayout(int padding) {
		_padding = padding;
	}
	
	public void setPadding(int padding) {
		_padding = padding;
	}
	
	public double getPadding() {
		return _padding;
	}

	public void layout(Vector<TheObject> v, Vector<TheOrientation> or, double x, double y, double w, double h) {
		for (int i = 0; i < v.size(); i++) {
			TheObject o = v.get(i);
			TheCompassOrientation orient = (TheCompassOrientation)or.get(i);
			switch(orient) {
			case NORTH:
				o.setLocation((w - o.getWidth())/2.0 + x, y + _padding);
				break;
			case SOUTH:
				o.setLocation((w - o.getWidth())/2.0 + x, h - o.getHeight() - _padding + y);
				break;
			case EAST:
				o.setLocation(w - o.getWidth() + x - _padding, (h - o.getHeight())/2.0 + y);
				break;
			case WEST:
				o.setLocation(x + _padding, (h - o.getHeight())/2.0 + y);
				break;
			case NORTHEAST:
				o.setLocation(w - o.getWidth() + x - _padding, y + _padding);
				break;
			case NORTHWEST:
				o.setLocation(x + _padding, y + _padding);
				break;
			case SOUTHEAST:
				o.setLocation(w - o.getWidth() + x - _padding, h - o.getHeight() + y - _padding);
				break;
			case SOUTHWEST:
				o.setLocation(x + _padding, y + h - o.getHeight() - _padding);
				break;
			case CENTER:
				o.setLocation((w - o.getWidth())/2.0 + x, (h - o.getHeight())/2.0 + y);
				break;
			}
		}
	}
}
